package com.itheima.exception.custom;

/**
 * @author Anomaly
 * @date 2023/2/6 21:17
 */
public class AgeDemo {
    public static void main(String[] args) {
//        try {
//            checkAge(2);
//        } catch (AgeIllegalException e) {
//            e.printStackTrace();
//        }
        try {
            checkAge(-2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("程序结束");
    }

    public static void checkAge(int age) {
        if (age > 0 && age < 200) {
            System.out.println("年龄合法");
        } else {
            throw new AgeIllegalRuntimeException("非法年龄");
        }
    }

//    public static void checkAge(int age) throws AgeIllegalException {
//        if (age > 0 && age < 200) {
//            System.out.println("年龄合法");
//        } else {
//            throw new AgeIllegalException("非法年龄");
//        }
//    }
}
